import { request } from 'umi';
import { getBaseUrl } from '@/services/urlconst';
import { getTenant } from '@/utils';
import { positionAPI } from './type';

let baseUrl = getBaseUrl();

/**
 *获取组织机构树列表  公司权限
 */
export async function getOrgTreeCompany(
  params: positionAPI.ITreeRequestType,
  type: any,
) {
  // type 为 true 是公司权限, 为false 是部门权限
  let url = type
    ? `${baseUrl}/positionController/getTreeByCompany`
    : `${baseUrl}/positionController/getTreeByDepart`;
  return request(url, {
    method: 'POST',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    data: {
      ...params,
    },
    requestType: 'json',
    charset: 'utf8',
    skipErrorHandler: true,
  });
}

/**
 * 获取组织机构树列表  岗位权限
 */
// export async function getOrgTreeDepart(params: positionAPI.ITreeRequestType) {
//   let url = `${baseUrl}/positionController/getTreeByDepart`;
//   return request(url, {
//     method: 'POST',
//     toObj: false,
//     headers: {
//       tenantName: getTenant(),
//     },
//     data: {
//       ...params,
//     },
//     requestType: 'json',
//     charset: 'utf8',
//     skipErrorHandler: true,
//   });
// }

/**
 * 获取岗位管理列表
 */
export async function getOrgPosition(params: positionAPI.ITableRequestType) {
  let url = `${baseUrl}/positionController/treeGrid/${params?.id}`;
  return request(url, {
    method: 'GET',
    toObj: false,
    headers: {
      tenantName: getTenant(),
    },
    skipErrorHandler: true,
  });
}
